#include <fstream>
#include <iostream>
#include <sstream>
#include "boost/filesystem.hpp"
#include "boost/filesystem/fstream.hpp"
#define BOOST_FILESYSTEM_NO_DEPRECATED

/**
 *
 * @author Remigiusz Rohulko, 9rohulko at orion.fis.agh.edu.pl
 * @date 14.01.2012
 * @brief Simple app for creating text files
 */

int char2int(const char* str) {
    std::stringstream ss;
    int temp;
    ss << str;
    ss >> temp;
    return temp;
}

namespace fs = boost::filesystem;

int main(int argc, char** argv) {
    if (argc<2) {
        std::cerr << "usage: filemaker <dir> <number of files> <size [Bytes]> " << std::endl;
        return 1;
    }
    fs::path full_path( fs::initial_path<fs::path>());
    full_path = fs::system_complete(fs::path( argv[1] ));
    if (!fs::create_directory(full_path)) {
        std::cerr << "Directory already exists!" << std::endl;
        return 1;
    }

    const unsigned      files = char2int(argv[2]);
    const unsigned      size  = char2int(argv[3]);
    const std::string   garbage("0123456789");
    const std::string   filename("file_");
    fs::ofstream        file;

    for (unsigned i=0; i<files; ++i) {
        std::ostringstream tmpFilename;
        tmpFilename << full_path.native_directory_string() << "/" << filename << i;
        file.open(tmpFilename.str().c_str(), std::ios::out);
        if (file.good()) {
            for (size_t j = 0; j<(int)(size/9); ++j) {
                file << "abcdefgh\n";
            }
            file.close();
        }
        tmpFilename.clear();
    }
    return 0;
}
